//
//  ZGWJiBingFengXianJiuZhengSecondTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/6/6.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ZGWJiBingFengXianJiuZhengSecondTableViewCell.h"

@implementation ZGWJiBingFengXianJiuZhengSecondTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withUserXinXiDic:(NSMutableDictionary *)dic
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubviewWithUserXinXiDic:dic];
    }
    return self;
}

// 布局
- (void)addMySubviewWithUserXinXiDic:(NSMutableDictionary *)userXinXiDic
{
    // 性别
    UILabel *gender = [[UILabel alloc] initWithFrame:CGRectMake(25 * kAdjustParamater, 10 * kAdjustParamater, 70 * kAdjustParamater, 20 * kAdjustParamater)];
    //   jiYinBianYi.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    gender.text = @"基因变异";
    gender.textColor = [UIColor blackColor];
    gender.textAlignment = NSTextAlignmentLeft;
    gender.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:gender];
    
    // 男Button
    self.nanButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.nanButton.frame = CGRectMake(125 * kAdjustParamater, gender.top + 2 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater);
    self.nanButton.layer.cornerRadius = self.nanButton.width / 2;
    self.nanButton.layer.masksToBounds = YES;
    [self.contentView addSubview:_nanButton];
    
    // 男label
    UILabel *nanLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nanButton.right + 10 * kAdjustParamater, gender.top, 35 * kAdjustParamater, 20 * kAdjustParamater)];
    nanLabel.text = @"男";
    nanLabel.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:nanLabel];
    
    // 女button
    self.nvButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.nvButton.frame = CGRectMake(nanLabel.right + 17 * kAdjustParamater, gender.top + 2 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater);
    self.nvButton.layer.cornerRadius = self.nanButton.width / 2;
    self.nvButton.layer.masksToBounds = YES;
    [self.contentView addSubview:_nvButton];
    
    // 女label
    UILabel *nvLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nvButton.right + 10 * kAdjustParamater, gender.top, 35 * kAdjustParamater, 20 * kAdjustParamater)];
    nvLabel.text = @"女";
    nvLabel.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:nvLabel];
    
    // 年龄
    UILabel *age = [[UILabel alloc] initWithFrame:CGRectMake(25 * kAdjustParamater, gender.bottom + 25 * kAdjustParamater, 70 * kAdjustParamater, 20 * kAdjustParamater)];
    age.text = @"年龄";
    age.textColor = [UIColor blackColor];
    age.textAlignment = NSTextAlignmentLeft;
    age.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:age];
    
    // 年龄tf
    self.ageTF = [[UITextField alloc] initWithFrame:CGRectMake(125 * kAdjustParamater, age.top, 50 * kAdjustParamater, 20 * kAdjustParamater)];
    self.ageTF.text = @"37";
    self.ageTF.textColor = kCyanColor;
    self.ageTF.tintColor = kCyanColor;
    self.ageTF.textAlignment = NSTextAlignmentLeft;
    self.ageTF.font = [UIFont systemFontOfSize:k17Big];
    self.ageTF.keyboardType = UIKeyboardTypeNumberPad;
    [self.contentView addSubview:_ageTF];
    
    // 身高
    UILabel *shenGao = [[UILabel alloc] initWithFrame:CGRectMake(25 * kAdjustParamater, age.bottom + 25 * kAdjustParamater, 70 * kAdjustParamater, 20 * kAdjustParamater)];
    shenGao.text = @"身高";
    shenGao.textColor = [UIColor blackColor];
 //   shenGao.textAlignment = NSTextAlignmentLeft;
    shenGao.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:shenGao];
    
    // 身高tf
    self.shenGaoTF = [[UITextField alloc] initWithFrame:CGRectMake(125 * kAdjustParamater, shenGao.top, 50 * kAdjustParamater, 20 * kAdjustParamater)];
    self.shenGaoTF.text = @"170";
    self.shenGaoTF.textColor = kCyanColor;
    self.shenGaoTF.tintColor = kCyanColor;
    self.shenGaoTF.textAlignment = NSTextAlignmentLeft;
    self.shenGaoTF.font = [UIFont systemFontOfSize:k17Big];
    self.shenGaoTF.keyboardType = UIKeyboardTypeNumberPad;
    [self.contentView addSubview:_shenGaoTF];
    
    // 体重
    UILabel *tiZhong = [[UILabel alloc] initWithFrame:CGRectMake(25 * kAdjustParamater, shenGao.bottom + 25 * kAdjustParamater, 70 * kAdjustParamater, 20 * kAdjustParamater)];
    tiZhong.text = @"体重";
    tiZhong.textColor = [UIColor blackColor];
    tiZhong.textAlignment = NSTextAlignmentLeft;
    tiZhong.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:tiZhong];
    
    // 体重tf
    self.tiZhongTF = [[UITextField alloc] initWithFrame:CGRectMake(125 * kAdjustParamater, tiZhong.top, 70 * kAdjustParamater, 20 * kAdjustParamater)];
    self.tiZhongTF.text = @"70";
    self.tiZhongTF.textColor = kCyanColor;
    self.tiZhongTF.tintColor = kCyanColor;
    self.tiZhongTF.textAlignment = NSTextAlignmentLeft;
    self.tiZhongTF.font = [UIFont systemFontOfSize:k17Big];
    self.tiZhongTF.keyboardType = UIKeyboardTypeNumberPad;
    [self.contentView addSubview:_tiZhongTF];
    
    // 进行用户信息的赋值
    
    // 性别
    NSString *genderString = [userXinXiDic valueForKey:@"性别"];
    if ([genderString isEqualToString:@"men"]) {
        [self.nanButton setBackgroundImage:[UIImage imageNamed:@"xuanzhong-jibingjiuzheng"] forState:UIControlStateNormal];
        [self.nvButton setBackgroundImage:[UIImage imageNamed:@"weixuanzhong-jibinghfengxian"] forState:UIControlStateNormal];
        nanLabel.textColor = [UIColor blackColor];
        nvLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    } else if ([genderString isEqualToString:@"women"]) {
        [self.nanButton setBackgroundImage:[UIImage imageNamed:@"weixuanzhong-jibinghfengxian"] forState:UIControlStateNormal];
        [self.nvButton setBackgroundImage:[UIImage imageNamed:@"xuanzhong-jibingjiuzheng"] forState:UIControlStateNormal];
        nanLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        nvLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:1];
    }
    
    // 年龄
    self.ageTF.text = [userXinXiDic valueForKey:@"年龄"];
    // 身高
    self.shenGaoTF.text = [userXinXiDic valueForKey:@"身高"];
    // 体重
    self.tiZhongTF.text = [NSString stringWithFormat:@"%@kg",  [userXinXiDic valueForKey:@"体重"]];
    
    // 身体质量指数
    UILabel *shenTiZhiLiangZhiShuLabel = [[UILabel alloc] initWithFrame:CGRectMake(25 * kAdjustParamater, tiZhong.bottom + 33 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
    shenTiZhiLiangZhiShuLabel.text = @"身体质量指数（BMI）";
    shenTiZhiLiangZhiShuLabel.textColor = [UIColor blackColor];
    shenTiZhiLiangZhiShuLabel.textAlignment = NSTextAlignmentLeft;
    shenTiZhiLiangZhiShuLabel.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:shenTiZhiLiangZhiShuLabel];
    
    // 身体健康指数图片
    UIImageView *shenTiJianKangZhiShuImageV = [[UIImageView alloc] initWithFrame:CGRectMake(75 / 2 * kAdjustParamater, shenTiZhiLiangZhiShuLabel.bottom + 10 * kAdjustParamater, 300 * kAdjustParamater, 115 * kAdjustParamater)];
    shenTiJianKangZhiShuImageV.image = [UIImage imageNamed:@"twoBMIImage-jibingjiuzheng"];
    [self.contentView addSubview:shenTiJianKangZhiShuImageV];
    
    // 体脂率
    UILabel *tiZhiLvLabel = [[UILabel alloc] initWithFrame:CGRectMake(25 * kAdjustParamater, shenTiJianKangZhiShuImageV.bottom + 5 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
    tiZhiLvLabel.text = @"体脂率";
    tiZhiLvLabel.textColor = [UIColor blackColor];
    tiZhiLvLabel.textAlignment = NSTextAlignmentLeft;
    tiZhiLvLabel.font = [UIFont systemFontOfSize:k17Big];
    [self.contentView addSubview:tiZhiLvLabel];
    
// 体脂率图片
    UIImageView *tiZhiLvImageV = [[UIImageView alloc] initWithFrame:CGRectMake(75 / 2 * kAdjustParamater, tiZhiLvLabel.bottom + 10 * kAdjustParamater, 300 * kAdjustParamater, 115 * kAdjustParamater)];
    tiZhiLvImageV.image = [UIImage imageNamed:@"twoTiZhiLv-jibingjiuzheng"];
    [self.contentView addSubview:tiZhiLvImageV];
    
    
    // 红色箭头的宽度
    float redWidthBMI = 0.0;
    // BMICount
    float BMICount = [[userXinXiDic valueForKey:@"BMI"] floatValue];
    // 0-18.5的比例
    float firstBiLiBMI = 300.0 / 4 / 185 * kAdjustParamater;
    // 18.5 - 24的比例
    float secondBiLiBMI = 300.0 / 4  / 55 * kAdjustParamater;
    // 24 - 28的比例
    float thirdBiLiBMI = 300.0 / 4 / 40 * kAdjustParamater;
    // 28 - 50的比例
    float fourthBiLiBMI = 300.0 / 4 / 220 * kAdjustParamater;
    if (BMICount <=18.5) {
        redWidthBMI = BMICount * 10 * firstBiLiBMI - 1.5 * kAdjustParamater;
    } else if (BMICount >18.5 && BMICount <= 24) {
        redWidthBMI = 75 * kAdjustParamater + (BMICount - 18.5) * 10 * secondBiLiBMI - 1.5 * kAdjustParamater;
    } else if (BMICount > 24 && BMICount <= 28) {
        redWidthBMI = 150 * kAdjustParamater + (BMICount - 24) * 10 * thirdBiLiBMI;
    } else if (BMICount > 28 && BMICount <= 50) {
        redWidthBMI = 225 * kAdjustParamater + (BMICount - 28) * 10 * fourthBiLiBMI;
    } else if (BMICount > 50) {
        redWidthBMI = 300 * kAdjustParamater;
    }
 //   NSLog(@"BMI数值 = %f", BMICount);

//    NSLog(@"BMI红色箭头width = %f", redWidthBMI);
    // 身体质量指数的红色箭头
    UIImageView *redJianTouOfShenTiJianKangZhiShu = [[UIImageView alloc] initWithFrame: CGRectMake(shenTiJianKangZhiShuImageV.left - 3.5 * kAdjustParamater + redWidthBMI , shenTiJianKangZhiShuImageV.top + 60 * kAdjustParamater, 7 * kAdjustParamater, 10 * kAdjustParamater)];
    redJianTouOfShenTiJianKangZhiShu.image = [UIImage imageNamed:@"redJiao-jibingjiuzheng"];
    [self.contentView addSubview:redJianTouOfShenTiJianKangZhiShu];
   
    // 体脂率
    float tiZhiCount = [[userXinXiDic valueForKey:@"体脂率"] floatValue];
    // 体脂率的红色箭头宽度
    float redWidthTiZhiLv = 0.0;
    // 0%-6%
    float firstBiLiTiZhiLv = 300.0 / 5 / 60 * kAdjustParamater;
    // 6%-14%
    float secondBiLiTiZhiLv = 300.0 / 5 / 80 * kAdjustParamater;
    // 14%-18%
    float thirdBiLiTiZhiLv = 300.0 / 5 / 40 * kAdjustParamater;
    // 18%-26%
    float fourthBiLiTiZhiLv = 300.0 / 5 / 80 * kAdjustParamater;
    // 26%-50%
    float fivethBiLiTiZhiLv = 300.0 / 5 / 240 * kAdjustParamater;
    if (tiZhiCount <= 6) {
        redWidthTiZhiLv = tiZhiCount * 10 * firstBiLiTiZhiLv;
    } else if (tiZhiCount > 6 && tiZhiCount <= 14) {
        redWidthTiZhiLv = 60 * kAdjustParamater + (tiZhiCount - 6) * 10 * secondBiLiTiZhiLv + 1.5 * kAdjustParamater;
    } else if (tiZhiCount > 14 && tiZhiCount <= 18) {
        redWidthTiZhiLv = 120 * kAdjustParamater + (tiZhiCount - 14) * 10 * thirdBiLiTiZhiLv;
    } else if (tiZhiCount > 18 && tiZhiCount <= 26) {
        redWidthTiZhiLv = 180 * kAdjustParamater + (tiZhiCount - 18) * 10 * fourthBiLiTiZhiLv + 1 * kAdjustParamater;
    } else if (tiZhiCount > 26 && tiZhiCount <= 50) {
        redWidthTiZhiLv = 240 * kAdjustParamater + (tiZhiCount - 26) * 10 * fivethBiLiTiZhiLv;
    } else if (tiZhiCount > 50) {
        redWidthTiZhiLv = 300 * kAdjustParamater;
    }
    UIImageView *tiZhiLvRedJianTouImageV = [[UIImageView alloc] initWithFrame:CGRectMake(tiZhiLvImageV.left - 3.5 * kAdjustParamater + redWidthTiZhiLv, tiZhiLvImageV.top + 60 * kAdjustParamater, 7 * kAdjustParamater, 10 * kAdjustParamater)];
    tiZhiLvRedJianTouImageV.image = [UIImage imageNamed:@"redJiao-jibingjiuzheng"];
    [self.contentView addSubview:tiZhiLvRedJianTouImageV];
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    self.bottomGrayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, tiZhiLvImageV.bottom + 5 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
    self.bottomGrayLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.07];
    [self.contentView addSubview:_bottomGrayLabel];
    
}


@end
